#include "menu.hpp"
#include "color.hpp"
#include "global.hpp"
#include "game_graphics.hpp"


#include<array>
#include<algorithm>
#include<iostream>
#include<sstream>


namespace {


	enum MainMenuStatusFlag {
		FLAG_NULL,
		FLAG_START_GAME,
		FLAG_CONTINUE_GAME,
		FLAG_DISPLAY_HIGHSCORES,
		FLAG_EXIT_GAME,
		MAX_NO_MAIN_MENU_STATUS_FLAGS
	};

	using mainmenustatus_t = std::array<bool, MAX_NO_MAIN_MENU_STATUS_FLAGS>;

	mainmenustatus_t mainmenustats{};

	bool FlagInputErrornousChoice{};

	void receive_input_flags(std::istream& in_os) {
		// Reset ErrornousChoice flag ...
		FlagInputErrornousChoice = bool{};
		char c;
		in_os >> c;

		switch (c)
		{
		case'1':
			mainmenustats[FLAG_START_GAME] = true;
			break;
		case'2':
			mainmenustats[FLAG_CONTINUE_GAME] = true;
			break;
		case'3':
			mainmenustats[FLAG_DISPLAY_HIGHSCORES] = true;
			break;
		case'4':
			mainmenustats[FLAG_EXIT_GAME] = true;
			break;
		default:
			FlagInputErrornousChoice = true;
			break;
		}
	}


	bool sololoop() {
		// No choice in Menu selected, reset all flags...
		mainmenustats = mainmenustatus_t{};
		clearScreen();
		DrawAlways(std::cout, Game::Graphics::AsciiArt2048);
		receive_input_flags(std::cin);
		return FlagInputErrornousChoice;
	}

	void endlessloop() {
		while (sololoop())
			;
	}

} //namespace

namespace Menu {

	void startMenu() {
		endlessloop();
	}

	void test_menu_1() {
		mainmenustatus_t mainmenustats{ true };
		std::cout << "This is " << __FUNCTION__ << std::endl;
		std::cout << mainmenustats[0] << '\n';
		std::cout << "\n	Just now!!!	______" << std::endl;

		//mainmenustats;
	}
}